/*
 * @Author: 颜礼田 2564217790@qq.com
 * @Date: 2024-09-07 11:15:17
 * @LastEditors: MrDotYan 2564217790@qq.com
 * @LastEditTime: 2024-09-10 22:54:39
 * @FilePath: /webServer/src/validator/role/role.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ApiProperty } from '@midwayjs/swagger';
import { getSchema, Rule, RuleType } from '@midwayjs/validate';
import { alternatives, StrIdValidator } from '..';
import { MenusSchema, PermissionSchema, RoleSchema } from '../../schema';

export class SaveRoleValidator implements RoleSchema {
  @ApiProperty({
    type: 'string',
    title: '角色编码',
    example: 'null',
    description: '角色编码',
    required: true,
  })
  @Rule(RuleType.string().required())
  roleCode: string;

  @ApiProperty({
    type: 'string',
    title: '角色名称',
    example: 'null',
    description: '角色名称',
    required: true,
  })
  @Rule(RuleType.string().required())
  roleName: string;

  @ApiProperty({
    type: Array<StrIdValidator>,
    items: {
      type: StrIdValidator,
    },
    title: '角色包含的菜单',
    example: 'null',
    description: '角色包含的菜单',
    required: true,
  })
  @Rule(RuleType.array().items(getSchema(StrIdValidator)).required())
  menus: MenusSchema[];

  @ApiProperty({
    type: Array<StrIdValidator>,
    items: {
      type: StrIdValidator,
    },
    title: '角色包含的菜单',
    example: 'null',
    description: '角色包含的菜单',
    required: true,
  })
  @Rule(RuleType.array().items(getSchema(StrIdValidator)).allow())
  permission: PermissionSchema[];
}

export class EditRoleValidator implements Partial<RoleSchema> {
  @ApiProperty({
    type: 'string',
    title: '角色编码',
    example: 'null',
    description: '角色编码',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  roleCode: string;
  @ApiProperty({
    type: 'string',
    title: '角色名称',
    example: 'null',
    description: '角色名称',
    required: false,
  })
  @Rule(RuleType.alternatives(alternatives))
  roleName?: string;

  @ApiProperty({
    type: Array<StrIdValidator>,
    items: {
      type: StrIdValidator,
    },
    title: '角色包含的菜单',
    example: 'null',
    description: '角色包含的菜单',
    required: true,
  })
  @Rule(RuleType.array().items(getSchema(StrIdValidator)).allow())
  menus: MenusSchema[];

  @ApiProperty({
    type: Array<StrIdValidator>,
    items: {
      type: StrIdValidator,
    },
    title: '角色包含的菜单',
    example: 'null',
    description: '角色包含的菜单',
    required: false,
  })
  @Rule(RuleType.array().items(getSchema(StrIdValidator)).allow())
  permission: PermissionSchema[];
}
